package main

func main() {
	// [344. 反转字符串](https://leetcode.cn/problems/reverse-string/)
	// [541. 反转字符串 II](https://leetcode.cn/problems/reverse-string-ii/)
	// [LCR 122. 路径加密](https://leetcode.cn/problems/ti-huan-kong-ge-lcof/)
	// [LCR 182. 动态口令](https://leetcode.cn/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof/)
}

// 344
func reverseString(s []byte) {
	left, right := 0, len(s)-1
	for left < right {
		s[left], s[right] = s[right], s[left]
		left++
		right--
	}
	return
}

// 541
func reverseStr(s string, k int) string {
	str := []byte(s)
	for i := 0; i < len(str); i += 2 * k {
		if i+k < len(str) {
			reverse(str[i : i+k])
		} else {
			reverse(str[i:])
		}
	}
	return string(str)
}
func reverse(s []byte) {
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
}

// LCR 122
func pathEncryption(path string) string {
	str := ""
	for _, v := range path {
		if string(v) != "." {
			str += string(v)
		} else {
			str += " "
		}
	}
	return str
}

// LCR 182
func dynamicPassword(password string, target int) string {
	// return password[target:] + password[:target]
	str := []byte(password)
	reverse(str, 0, target-1)
	reverse(str, target, len(password)-1)
	reverse(str, 0, len(password)-1)
	return string(str)
}
func reverse(str []byte, l, r int) {
	for l < r {
		str[l], str[r] = str[r], str[l]
		l++
		r--
	}
}
